package com.xiaotao.test01.websocket;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.util.JSONObject1O;
import com.xiaotao.test01.entity.Result;
import lombok.extern.slf4j.Slf4j;

import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * @author xiaotao
 */
@Slf4j
public class CustomerEnCoder implements Encoder.Text<Result> {
    @Override
    public String encode(Result object) throws EncodeException {
        byte[] encode = Base64.getEncoder().encode(JSONObject.toJSONString(object).getBytes());
        log.debug("CustomerEnCoder:{}",JSON.toJSONString(object));
        return new String(encode);
    }

    @Override
    public void init(EndpointConfig endpointConfig) {

    }

    @Override
    public void destroy() {

    }
}
